﻿using System;
using System.Data;
using System.Linq.Expressions;

namespace Dapper.Library
{
    /// <summary>
    /// 指令集
    /// </summary>
    public class CommandSql<T> : Command<T>, ICommandSql<T>
    {
        public CommandSql(IDbConnection conn, SqlProvider sqlProvider) : base(sqlProvider, conn)
        {
            SqlProvider.SetContext.TableType = typeof(T);
        }

        public CommandSql(IDbConnection conn, SqlProvider sqlProvider, IDbTransaction dbTransaction) : base(sqlProvider, conn, dbTransaction)
        {
            SqlProvider.SetContext.TableType = typeof(T);
        }

        internal CommandSql(IDbConnection conn, SqlProvider sqlProvider, Type tableType, LambdaExpression whereExpression) : base(sqlProvider, conn)
        {
            SqlProvider.SetContext.TableType = tableType;
            SqlProvider.SetContext.WhereExpression = whereExpression;
        }

        /// <summary>
        /// 使用SQL执行Command语句
        /// </summary>
        /// <param name="predicate"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public CommandSql<T> BySql(string predicate, object parameter)
        {
            SqlProvider.SetContext.SqlString = predicate;
            SqlProvider.SetContext.Params = parameter;
            return this;
        }

    }
}
